package boundarys;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JButton;

import ccrm.BoundryControl;
import controllers.UserController;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JLabel;

import entitys.Session;

import java.awt.Font;
import java.awt.Color;
import java.io.IOException;
import java.awt.GridLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;

public class MGUI extends AbstractGUI{

	private JFrame frmCcrmM;
	private String userid;
	private String userpw;
	

	/**
	 * Create the application.
	 */
	public MGUI(String userid, String userpw) {
		this.userid = userid;
		this.userpw = userpw;
		initialize();
		initGUI(frmCcrmM);
		frmCcrmM.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{140, 190, 123, 0};
		gridBagLayout.rowHeights = new int[]{147, 48, 55, 52, 39, 45, 73, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		frmCcrmM.getContentPane().setLayout(gridBagLayout);
		
		JLabel lblMarketingManPanel = new JLabel("Marketing Man Panel");
		lblMarketingManPanel.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		GridBagConstraints gbc_lblMarketingManPanel = new GridBagConstraints();
		gbc_lblMarketingManPanel.fill = GridBagConstraints.BOTH;
		gbc_lblMarketingManPanel.insets = new Insets(0, 0, 5, 5);
		gbc_lblMarketingManPanel.gridx = 1;
		gbc_lblMarketingManPanel.gridy = 0;
		frmCcrmM.getContentPane().add(lblMarketingManPanel, gbc_lblMarketingManPanel);
		
		JButton defineProductBtn = new JButton("Define Product");
		defineProductBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(BoundryControl.GUIArr.size()==getIndex()+1)//last on GUI's list
				{
					 new DefineProductGUI();
				}
				//frmCcrmM.setVisible(false);
			}
		});
		GridBagConstraints gbc_defineProductBtn = new GridBagConstraints();
		gbc_defineProductBtn.fill = GridBagConstraints.BOTH;
		gbc_defineProductBtn.insets = new Insets(0, 0, 5, 5);
		gbc_defineProductBtn.gridx = 1;
		gbc_defineProductBtn.gridy = 2;
		frmCcrmM.getContentPane().add(defineProductBtn, gbc_defineProductBtn);
		defineProductBtn.setVisible(true);
		
		JButton logOut = new JButton("Log Out");
		logOut.setForeground(Color.RED);
		logOut.setFont(new Font("Tahoma", Font.BOLD, 11));
		logOut.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(BoundryControl.GUIArr.size()==getIndex()+1)
				{
					goBack();
					UserController.LogoutUser(getUserid(), getUserpw());
				}
			}
		});
		GridBagConstraints gbc_logOut = new GridBagConstraints();
		gbc_logOut.insets = new Insets(0, 0, 5, 5);
		gbc_logOut.fill = GridBagConstraints.BOTH;
		gbc_logOut.gridx = 0;
		gbc_logOut.gridy = 4;
		frmCcrmM.getContentPane().add(logOut, gbc_logOut);
		logOut.setVisible(true);
		frmCcrmM.setVisible(true);
	}

	public String getUserpw() {
		return userpw;
	}

	public void setUserpw(String userpw) {
		this.userpw = userpw;
	}

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmCcrmM = new JFrame();
		frmCcrmM.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				UserController.LogoutUser(getUserid(), getUserpw());
			}
		});
		frmCcrmM.setResizable(false);
		frmCcrmM.setTitle("CCRM>Marketing Man Management");
		frmCcrmM.setBounds(100, 100, 362, 247);
		frmCcrmM.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	@Override
	public void getReply(Object r) {
		// TODO Auto-generated method stub

		
	}
}
